class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        //利用滑动窗口写一个
        int left = 0;
        int right = left;
        int sum = 0;
        int res = 0;
        while(right<nums.size())
        {
            sum+=nums[right];
            while(sum >= target)
            {
                if(res > right-left+1 || res == 0)
                res = right-left+1;
                sum -=nums[left];
                left++;
            }
            right++;
        }

    return res;
    }
};
